package distribuicaoDeProfessores;

/**
 *
 * @author Jaime
 */
public class RegistroDeHorario extends javax.swing.JPanel {
    Horario horario;
    Disciplinas disciplinas;
    /** Creates new form RegistroDeHorario */
    public RegistroDeHorario(Horario horario, Disciplinas disciplinas) {
        initComponents();
        this.horario = horario;
        this.disciplinas = disciplinas;
    }

    public void comboboxmodelDisciplina(Disciplinas disciplinas){
        
        if (disciplinas.disciplinas.isEmpty()) return;
        String[] nomes = new String[disciplinas.disciplinas.size()];
        for(int i = 0; i < disciplinas.disciplinas.size(); i++)
            nomes[i]= disciplinas.disciplinas.get(i).getNome();
    
       comboBoxDisciplina.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        
    }
    
     public void comboboxmodelHorario(Horario horario){
        
        if (horario.getHorario().isEmpty()) return;
        String[] nomes = new String[horario.getHorario().size()];
        for(int i = 0; i < horario.getHorario().size(); i++)
            nomes[i]= horario.getHorario().get(i).toString();
    
       comboBoxHorario.setModel(new javax.swing.DefaultComboBoxModel(nomes));
        
    }
     
    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        //Campo de texto local
          //Cria um item de horario: diciplina + professor(será sorteado)+local;
       try{
        if(textFieldLocal.getText().equals("")){
            javax.swing.JOptionPane.showMessageDialog(null, "O campo local esta vazio!", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }
        ItensHorario item = new ItensHorario(disciplinas.getDisciplinas().get(comboBoxDisciplina.getSelectedIndex()),
                                             textFieldLocal.getText()
                                            );
        
        horario.getHorario().get(comboBoxHorario.getSelectedIndex()).setNovoItem(item);//Colocando um Inter de horario no horario escolhido
        javax.swing.JOptionPane.showMessageDialog(null, item);
       }  catch(ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException )
      {
          javax.swing.JOptionPane.showMessageDialog(null, "É necessario ter um horario e uma disciplina\ncadastrados primeiro.", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        comboBoxDisciplina = new javax.swing.JComboBox();
        textFieldLocal = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        comboBoxHorario = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        cadastrar = new javax.swing.JButton();

        setBackground(new java.awt.Color(153, 204, 255));
        setLayout(new java.awt.BorderLayout());

        jLabel1.setFont(new java.awt.Font("Script MT Bold", 0, 48));
        jLabel1.setText("Registro de Horário");
        add(jLabel1, java.awt.BorderLayout.PAGE_START);

        jScrollPane1.setBackground(new java.awt.Color(153, 204, 255));

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 14));
        jLabel2.setText("Disciplina");

        comboBoxDisciplina.setFont(new java.awt.Font("Tahoma", 0, 12));

        textFieldLocal.setColumns(50);
        textFieldLocal.setFont(new java.awt.Font("Times New Roman", 0, 14));
        textFieldLocal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldLocalActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 14));
        jLabel4.setText("Local ");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 14));
        jLabel5.setText("Horario");

        cadastrar.setBackground(new java.awt.Color(51, 102, 255));
        cadastrar.setFont(new java.awt.Font("Times New Roman", 1, 14));
        cadastrar.setForeground(new java.awt.Color(255, 255, 255));
        cadastrar.setText("Cadastrar");
        cadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboBoxDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(193, 193, 193))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(comboBoxHorario, 0, 270, Short.MAX_VALUE)
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(472, Short.MAX_VALUE)
                .addComponent(cadastrar)
                .addGap(50, 50, 50))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(textFieldLocal)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(294, 294, 294))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboBoxDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textFieldLocal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                .addComponent(cadastrar)
                .addGap(63, 63, 63))
        );

        jScrollPane1.setViewportView(jPanel1);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void cadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastrarActionPerformed
        // Botao Cadastrar
        //Cria um item de horario: diciplina + professor(será sorteado)+local;
       try{
        if(textFieldLocal.getText().equals("")){
            javax.swing.JOptionPane.showMessageDialog(null, "O campo local esta vazio!", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }
        ItensHorario item = new ItensHorario(disciplinas.getDisciplinas().get(comboBoxDisciplina.getSelectedIndex()),
                                             textFieldLocal.getText()
                                            );
        
        horario.getHorario().get(comboBoxHorario.getSelectedIndex()).setNovoItem(item);//Colocando um Inter de horario no horario escolhido
        javax.swing.JOptionPane.showMessageDialog(null, item);
       }  catch(ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException )
      {
          javax.swing.JOptionPane.showMessageDialog(null, "É necessario ter um horario e uma disciplina\ncadastrados primeiro.", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
    }//GEN-LAST:event_cadastrarActionPerformed

    private void textFieldLocalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldLocalActionPerformed
               //Cria um item de horario: diciplina + professor(será sorteado)+local;
       try{
        if(textFieldLocal.getText().equals("")){
            javax.swing.JOptionPane.showMessageDialog(null, "O campo local esta vazio!", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }
        ItensHorario item = new ItensHorario(disciplinas.getDisciplinas().get(comboBoxDisciplina.getSelectedIndex()),
                                             textFieldLocal.getText()
                                            );
        
        horario.getHorario().get(comboBoxHorario.getSelectedIndex()).setNovoItem(item);//Colocando um Inter de horario no horario escolhido
        javax.swing.JOptionPane.showMessageDialog(null, item);
       }  catch(ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException )
      {
          javax.swing.JOptionPane.showMessageDialog(null, "É necessario ter um horario e uma disciplina\ncadastrados primeiro.", "Erro!!!", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
    }//GEN-LAST:event_textFieldLocalActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cadastrar;
    private javax.swing.JComboBox comboBoxDisciplina;
    private javax.swing.JComboBox comboBoxHorario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField textFieldLocal;
    // End of variables declaration//GEN-END:variables
}
